package com.example.demo.firemain.data;


import com.example.demo.firemain.ByteUtil;
import lombok.Data;

import java.text.SimpleDateFormat;

/**
 * 设备状态正常
 * 部件状态
 *
 * @author TDS
 * @date 2022/08/23
 */
@Data
public class DeviceStatusGuoBiaoNormal {


	/**
	 * 状态
	 */
	private Integer status;

	/**
	 * 设备id
	 */
	private String device_id;

	private UserMessage userMessage;
	public static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

	public DeviceStatusGuoBiaoNormal(String message, String deviceId) {

		this.device_id = deviceId;

		userMessage = new UserMessage();
		userMessage.setSystemType(Integer.parseInt(message.substring(0, 2), 16));
		userMessage.setFireMainCode(Integer.parseInt(message.substring(2, 4), 16));
		userMessage.setPartType(Integer.parseInt(message.substring(4, 6), 16));
		userMessage.setAddressNo(String.valueOf(Integer.parseInt(message.substring(8, 10) +
				message.substring(6, 8), 16)));

		userMessage.setLoopNo(String.valueOf(Integer.parseInt(message.substring(12, 14) +
				message.substring(10, 12), 16)));
		String bit_stat = ByteUtil.buqi(Integer.toBinaryString(Integer.parseInt(message.substring(14, 18), 16)));
		status = 2;

		userMessage.setPartStat("正常");


		String time = message.substring(30);
		String ms = String.valueOf(Integer.parseInt(time.substring(0, 2), 16));
		String min = String.valueOf(Integer.parseInt(time.substring(2, 4), 16));
		String hour = String.valueOf(Integer.parseInt(time.substring(4, 6), 16));
		String day = String.valueOf(Integer.parseInt(time.substring(6, 8), 16));
		String month = String.valueOf(Integer.parseInt(time.substring(8, 10), 16));
		String year = String.valueOf(Integer.parseInt(time.substring(10), 16));

		userMessage.setUpTime("20" + year + "-" + month + "-" + day + " " + hour + ":" + min + ":" + ms);

	}
}
